package com.xy.mainp.base;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;

import com.xy.mainp.R;
import com.xy.mainp.main.widget.TittleBar;
import com.xy.mainp.utils.StatusBarUtil;

/**
 * Created by John on 2016/11/1.
 */

public class TittleBarFragmnet extends LazyFragment {

    private TittleBar tittleBar;
    private Context mContext;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        initTittleBar();
        super.onCreate(savedInstanceState);

    }

    @Override
    public void onAttach(Context context) {
        this.mContext = context;
        super.onAttach(context);
    }

    private void initTittleBar() {
        tittleBar = TittleBar.initTittleBar(new FrameLayout(getContext()));
        StatusBarUtil.setImmersiveStatusBar(getActivity(),getResources().getColor(R.color.title_bar));
        super.setContentView(tittleBar.getContainer());
    }
    private View rootView;

    @Override
    public View setContentView(View view) {
        this.rootView = view;
        if (tittleBar != null) {
            tittleBar.setContentView(rootView);
        } else {
            super.setContentView(rootView);
        }
        return rootView;
    }

    public void setTittleBar(TittleBar tittleBar){
        if (tittleBar != null){
            tittleBar.attachedTo(this.tittleBar.getContainer());
            this.tittleBar = tittleBar;
        }
    }

    @Override
    public Context getContext() {
        Context context =  super.getContext();
        if (context == null){
            return mContext;
        }
        return context;
    }

    public TittleBar getTittleBar() {
        return tittleBar;
    }
}
